import QtQuick 1.0
import com.nokia.meego 1.0
import "UIConstants.js" as UI

Item {
    id: root

    property alias titleText: title.text
    property bool selected: index == root.ListView.view.currentIndex
    property bool isFolder

    signal clicked

    height: UI.LIST_ITEM_HEIGHT_DEFAULT
    width: ListView.view.width

    property string __colorString: "color19-"
    property bool inverted: theme.inverted
    property string __invertedString: inverted? "-inverted" : ""
    property url highlightBackground: "image://theme/" + __colorString + "meegotouch-list-fullwidth" + __invertedString + "-background-selected"

    BorderImage {
        id: background
        anchors.fill: parent
        border { left: UI.CORNER_MARGINS; top: UI.CORNER_MARGINS; right: UI.CORNER_MARGINS; bottom: UI.CORNER_MARGINS }
        source: root.selected ? root.highlightBackground : ""
    }

    Row {
        spacing: 5
        anchors.verticalCenter: parent.verticalCenter

        Image {
            id: fileIcon
            source: isFolder ? "image://theme/icon-m-common-directory" : "image://theme/icon-m-content-document"
            anchors.verticalCenter: parent.verticalCenter
        }
        Text {
            id: title
            anchors.verticalCenter: parent.verticalCenter
            width: isFolder ? root.width - fileIcon.width - rightIcon.width - 10 : root.width - fileIcon.width - 5
            font.pixelSize: UI.FONT_SLARGE
            font.bold: true
            color: UI.COLOR_FOREGROUND
            elide: Text.ElideRight
        }
        ToolIcon {
            id: rightIcon
            visible: isFolder
            platformIconId: "toolbar-next"
        }
    }

    MouseArea {
        anchors.fill: parent
        onClicked: root.clicked()
        onPressed: {
            root.ListView.view.currentIndex = index;
        }
        onReleased: {
            root.ListView.view.currentIndex = -1;
        }
        onCanceled: {
            root.ListView.view.currentIndex = -1;
        }
    }
}
